home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / xpat2-1.000 / xpat2-1 / xpat2-1.04 / src / Xlib-buttons.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  5KB  |  157 lines

  1. /*****************************************************************************/
  2. /*                                         */
  3. /*                                         */
  4. /*    X patience version 2 -- module Xlib-buttons.c                 */
  5. /*                                         */
  6. /*    Management of the button area for the Xlib interface             */
  7. /*    written by Heiko Eissfeldt and Michael Bischoff                 */
  8. /*    see COPYRIGHT.xpat2 for Copyright details                 */
  9. /*                                         */
  10. /*                                         */
  11. /*****************************************************************************/
  12. #ifdef useXlib
  13. #include "X-pat.h"
  14. #ifndef NO_ROUND_CARDS
  15. #include    <X11/Xmu/Drawing.h>
  16. #endif
  17.  
  18.  
  19. struct confirm confirm = { 0 };
  20. Window finished_win;
  21.  
  22. void show_message(const char *str, ...) {
  23.     static char last_message[512] = " ";
  24.  
  25.     if (str) {
  26.     va_list args;
  27.     va_start(args, str);
  28.     vsprintf(last_message, str, args);
  29.     }
  30.     XFillRectangle(dpy, table, whitegc, 0, graphic.buttons_height,
  31.            graphic.width, graphic.message_height);
  32.     XDrawRectangle(dpy, table, blackgc, 0, graphic.buttons_height,
  33.            graphic.width-1, graphic.message_height-1);
  34.     XDrawImageString(dpy, table, graphic.textgc, graphic.message_x, graphic.message_y,
  35.     last_message, strlen(last_message));
  36. }
  37.  
  38. static void (*execfunc)(void) = NULL;
  39.  
  40. void request_confirm(void (*dofunc)(void), const char *prompt) {
  41.     if (execfunc)
  42.     return;        /* request pending => deny another one */
  43.     execfunc = dofunc;
  44.     confirm.text = prompt;
  45.     XMapWindow(dpy, confirm.win);
  46. }
  47.  
  48. void cmd_Cancel(void) {
  49.     if (execfunc) {
  50.     execfunc = NULL;
  51.     XUnmapWindow(dpy, confirm.win);
  52.     }
  53. }
  54.  
  55. void cmd_Confirm(void) {
  56.     if (execfunc) {
  57.     (*execfunc)();
  58.     cmd_Cancel();
  59.     }
  60. }
  61.  
  62. void redraw_buttons(int x, int y, int w, int h, Window win, int num, struct singlebutton *p) {
  63.     while (num--) {
  64.     if (x >= p->x + p->w || x + w < p->x ||
  65.         y >= p->y + p->h || y + h < p->y) {    /* does not intersect */
  66.         ++p;
  67.         continue;
  68.         }
  69. #ifndef NO_ROUND_CARDS
  70.     if (B_ROUND_W)    {
  71.         /* fill the background */
  72.         XmuFillRoundedRectangle(dpy, win, whitegc, p->x, p->y, 
  73.         p->w-1, p->h-1, B_ROUND_W, B_ROUND_H);
  74.         /* draw the text */
  75.             XDrawImageString(dpy, win, button.gc, p->x + button.bx, p->y +
  76.              button.by + button.font->ascent, p->text, strlen(p->text));
  77.         /* draw border on button */
  78.         XmuDrawRoundedRectangle(dpy, win, blackgc, p->x, p->y, 
  79.         p->w-1, p->h-1, B_ROUND_W, B_ROUND_H);
  80.     } else    
  81. #endif
  82.     {
  83.         /* fill the background */
  84.         XFillRectangle(dpy, win, whitegc, p->x, p->y, p->w-1, p->h-1);
  85.         /* draw the text */
  86.             XDrawImageString(dpy, win, button.gc, p->x + button.bx, p->y +
  87.              button.by + button.font->ascent, p->text, strlen(p->text));
  88.         /* draw border on button */
  89.         XDrawRectangle(dpy, win, blackgc, p->x, p->y, p->w-1, p->h-1);
  90.     }
  91.     ++p;
  92.  
  93.     }
  94. }
  95.  
  96. #ifdef DEBUG
  97. void cmd_DebugOut(void);
  98.  
  99. void cmd_DebugOut(void) {
  100.     int i, j;
  101.     static const char *vis[2] = { "hidden ", "" };
  102.  
  103.     printf("Debugging output:\ngame.ind[] = \n{");
  104.  
  105.     for (i = 0; i <= game.numpiles; ++i)
  106.     printf(" %d", game.ind[i]);
  107.     printf(" }\n");
  108.     for (i = 0; i < rules.numstacks+rules.numslots/*game.numpiles*/; ++i) {
  109.     struct pile *p;
  110.     p = &graphic.pile[i];
  111.     printf((i < rules.numstacks ? "Stack %d: " : "Slot %d: "),
  112.            (i < rules.numstacks ? i : i - rules.numstacks));
  113.     printf("pos (%d,%d) c=%d, max=%d\n  ", p->x, p->y, p->xtotal, p->xmaxheight);
  114.     for (j = game.ind[i]; j < game.ind[i+1]; ++j)
  115.         if (IS_JOKER(game.cards[j]))
  116.         printf("Joker!");
  117.         else
  118.         printf("%s%s %s  ", vis[game.visible[j]],
  119.         US_rank_name[RANK(game.cards[j])],
  120.         US_suit_name[SUIT(game.cards[j])]);
  121.     printf("\n");
  122.     }
  123. }
  124.  
  125. #endif
  126.  
  127. struct buttons button = {
  128.     0,
  129.     4, 4,
  130.     3, 3,
  131.     0, 0, 0,
  132.     {
  133.     { 0, 0, 0, 0, "quit",          rq_LeavePat,     rq_LeavePat,   rq_LeavePat },
  134.     { 0, 0, 0, 0, "cards",          cmd_DealCards,   cmd_DealCards, cmd_DealCards },
  135.     { 0, 0, 0, 0, "undo",          cmd_UndoMove,    cmd_UndoMove,  cmd_UndoMove },
  136.     { 0, 0, 0, 0, "redo",          cmd_RedoMove,    cmd_RedoMove,  cmd_RedoMove },
  137.     { 0, 0, 0, 0, "restart",      cmd_RestartGame, NULL, NULL },
  138.     { 0, 0, 0, 0, "new game",     rq_AnotherGame,  NULL, NULL },
  139.     { 0, 0, 0, 0, "score",            cmd_ShowScore,   cmd_ShowScore, cmd_ShowScore },
  140.     { 0, 0, 0, 0, "hint",          cmd_NextHint,    cmd_DoHint,    cmd_PreviousHint },
  141.     { 0, 0, 0, 0, "move to stack",     cmd_ToStack,     cmd_ToStack,   cmd_ToStack },
  142.     { 0, 0, 0, 0, "replay",        cmd_ReplayGame,     NULL, NULL },
  143.     { 0, 0, 0, 0, "save",        cmd_SaveGame,     NULL, NULL },
  144. #ifdef DEBUG
  145.     { 0, 0, 0, 0, "debug",        cmd_DebugOut,     NULL, NULL },
  146. #endif
  147.     { 0, 0, 0, 0, NULL, NULL, NULL, NULL }
  148.     }
  149. };
  150.  
  151. struct singlebutton confirmbuttons[3] = {
  152.     { 0, 0, 0, 0, "confirm",  cmd_Confirm, NULL, NULL },
  153.     { 0, 0, 0, 0, "cancel",      cmd_Cancel, NULL, NULL },
  154.     { 0, 0, 0, 0, NULL, NULL, NULL, NULL }
  155. };
  156. #endif
  157.